package com.jackrain.nea.fc.dl.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wuwenxue
 * @date 2018/05/22
 **/
@Mapper
public interface ViewDLPurRetToF4Mapper {

    @SelectProvider(type = ViewDLPurRetSql.class, method = "findPurRetData")
    List<HashMap> selPurRetData(@Param("id") Object[] id,
                                @Param("send_status") Integer send_status,
                                @Param("status") Integer status,
                                @Param("isactive") String isactive);

    @SelectProvider(type = ViewDLPurRetSql.class, method = "findPurRetItemData")
    List<HashMap> selPurRetItemData(@Param("id") Long id);

    @Select("SELECT ECODE FROM DL_C_BILLDIM_ITEM WHERE ID=#{id}")
    String selbillType(Long id);

    class ViewDLPurRetSql {

        public String findPurRetData(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("id");
            Integer send_status = (Integer) map.get("send_status");
            Integer status = (Integer) map.get("status");
            String isactive = (String) map.get("isactive");
            return new SQL() {
                {
                    SELECT("ID,BILL_NO,CP_C_SUPPLIER_ECODE,CP_C_STORE_ECODE,BILL_DATE,REFUND_TYPE,REMARK," +
                            "CREATIONDATE,OWNERENAME,MODIFY_BILL_NO,MODIFIERNAME,MODIFIERENAME,MODIFIEDDATE,BILL_SOURCE,LOGISTICS_BILL_NO,CARRIER_NAME");
                    FROM("DL_B_PUR_RET");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE("ID IN (" + sb.toString() + ")");
                    if (null != send_status) {
                        WHERE("SEND_STATUS = " + send_status);
                    }
                    if (null != status) {
                        WHERE("STATUS = " + status);
                    }
                    if (null != isactive) {
                        WHERE("ISACTIVE = '" + isactive + "'");
                    }
                }
            }.toString();
        }

        public String findPurRetItemData(Map<String, Object> map) {
            Long id = (Long) map.get("id");
            return new SQL() {
                {
                    SELECT("PS_C_SKU_ECODE,QTY_BILL,QTY_OUT,AMT_ACTUAL,PRICE_ACTUAL,AMT_ACTUAL_OUT,DPRICE_LIST,PRICE_MGT,AMT_MGT,PRICE_NON_TAX,AMT_NON_TAX");
                    FROM("DL_B_PUR_RET_ITEM");
                    WHERE("DL_B_PUR_RET_ID =" + id);
                }
            }.toString();
        }


    }


}
